package xiao.ke.serviceinvoker1.controller;/**
 * @author XuXiaoK
 * @create 2020-01-20 14:15
 */

import com.netflix.hystrix.HystrixCircuitBreaker;
import com.netflix.hystrix.HystrixCommandKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;
import xiao.ke.serviceinvoker1.service.BookService;
import xiao.ke.serviceinvoker1.service.HelloClient;
import xiao.ke.serviceinvoker1.service.HelloService;

/**
 *@Author XiaoKe
 *@Date 2020/1/20 14:15
 *@Description TODO
 */
@RestController
@Configuration
public class HelloControler {

    @Autowired
    HelloService helloService;



    @Autowired
    private HelloClient helloClient;
    @RequestMapping(value = "/Hello", method = RequestMethod.GET)
    public String hello(){
        return "";
    }

    @RequestMapping(value = "/hello")
    public String hi(@RequestParam String name){
        return helloService.hiService(name);
    }

    @RequestMapping("/hi")
    public String hello1() {
        return helloService.router();

    }

    @GetMapping("feign/hello")
    public String feignHello() {
        String s = helloClient.hello();
        HystrixCircuitBreaker breaker = HystrixCircuitBreaker.Factory
                .getInstance(HystrixCommandKey.Factory
                        .asKey("HelloClient#hello()"));
        System.out.println("断路器状态：" + breaker.isOpen());
        return s;
    }
}